A US man is seeking damages after a police officer took photographs of him masturbating when he was 17, hoping to use the images as evidence in a sexting trial.

Trey Sims was under investigation for sending explicit images to his 15-year-old girlfriend when detective David Abbott obtained a warrant to photograph his "erect penis" so it could be compared to a penis sent to the girl's phone.

Sims was unable to muster an erection in the presence of armed officers and Abbott, who then obtained a second warrant to take him to a hospital and "give him an erection-producing injection".

The second warrant was not carried out when, in 2014, the case provoked national outrage. The initial photographs taken by Abbott were never used as evidence.

Abbott committed suicide in December 2016 when police came to arrest him in connection with molesting two young boys – accusations unrelated to the Sims case.

Now Sims is suing Abbott's estate for violating his person. On 5 December, a federal appeals court ruled that the warrant against him was an "obvious, unconstitutional violation" and that the action could proceed at district court level.

"A reasonable police officer would have known that attempting to obtain a photo of a minor child's erect penis, by ordering the child to masturbate in the presence of others, would unlawfully invade the child's right to privacy under the fourth amendment," 4th Circuit judges wrote in their ruling.

The whole episode began when Sims sent a video to his minor girlfriend of himself "fondling his erect penis", the ruling states.

Abbott then obtained a warrant for "photographs of the genitals, and other parts of the body of [Sims] that will be used as comparisons in recovered forensic evidence from the victim and suspect's electronic devices. This includes a photograph of the suspect's erect penis."

Detective David Abbott
Detective David Abbott killed himself in the wake of unrelated paedophilia accusations Manassas City Police Department

Abbott detained the teen and took him to a locker room in a juvenile facility where, in the presence of two armed officers, he ordered him to "pull down his pants so a photo could be taken of his penis" and "use his hand to manipulate his penis in different ways".

Sims was unable to get an erection so Abbott, using his own cell phone, made do with taking pictures of the youngster's flaccid member.

The second warrant was obtained the following day but never carried out in the face of intense pressure from the public and media.

Sims served a year on probation for his sexting exploits after a juvenile court deferred its finding.