A weird fetish is helping a Manhattan prosecutor’s allegedly pervy hubby get off — in court.

Matthew Seltzer, married to Assistant District Attorney Lauren Angelo-Seltzer, was accused in January 2018 of installing a spy camera to capture the family’s 23-year-old nanny, Vanessa Rivas, changing in a bathroom.

At first, the Seltzers maintained they had no knowledge of the device and insisted it was planted by a mystery Peeping Tom.

Now Matthew Seltzer is confessing to inserting the spycam in the bathroom himself to act on a bizarre fetish — of seeing himself undress, sources said.

Even crazier: The Brooklyn District Attorney’s Office may be buying the alibi and is considering dropping the case against the accused perv.

“No explanation as to why he would need a hidden, disguised camera with motion activation to film himself, as far as we are aware,” said Rivas’ attorney, Vincent White.

The lawyer said prosecutors have yet to present Seltzer’s case to a grand jury, despite telling the nanny that jurors would hear the case over the summer.

“Apparently, they are actively considering dropping the case because of this new defense . . . They’re putting Vanessa’s life on hold to protect this pervert,” White seethed.

“It’s good to have connections and money I guess,” he said, describing the new developments as “apparent abuses of power.”

In addition to his wife working at the Manhattan DA’s Office, Seltzer’s mother-in-law is a retired Manhattan Criminal Court judge and former state Joint Commission on Public Ethics (JCOPE) appointee who married a Bronx prosecutor in a ceremony officiated by then-Mayor Rudy Giuliani.

Rivas was preparing to shower in the guest bathroom at the Seltzers’ StuyTown apartment on Jan. 18, 2018, when she noticed a device that resembled a black USB power adapter pointing toward her.

“It was in the bathroom just over the sink,” Rivas said in an interview earlier last year. “The sink is right next to the shower, so that is where you would undress just before hopping in.”

To Rivas’ horror, she discovered the device was a camera.

“I felt humiliated,” she said. “This is where I would undress multiple times. I showered there multiple times.”

When Angelo-Seltzer returned home from work, Rivas confronted the mother of three, who became “hostile” and snatched the spycam away, according to Rivas.

But the nimble nanny held onto the key piece of evidence: the camera’s microchip.

After Rivas left, the ADA phoned her 45 times and sent 26 text messages, according to court papers.

“Matt and I would never ever ever do this and I have no idea how or why you think we would, so we need that chip,” she wrote to Rivas in one exchange, according to screenshots of the texts shared with The Post.

Angelo-Seltzer claimed to cops that she had no idea who installed the device and that she was the subject of unlawful surveillance herself.

The first moments of footage captured by the camera show a woman, who Rivas said is Angelo-Seltzer, rustling through cabinets while wearing a coat and backpack, as if preparing for the workday.

The camera also captured StuyTown maintenance crews working in the bathroom throughout the day.

The final image shows Rivas reaching for the camera.

Rivas filed a criminal complaint against the couple at a Manhattan police station the following day. The case was later referred to the Brooklyn district attorney to avoid a conflict of interest.

After Rivas’ disturbing discovery, the couple launched a “campaign of intimidation and harassment” against her, court papers allege, including enlisting Angelo-Seltzer’s judge mom, Eileen Koretz, to lean on Rivas to drop the charges.

“I know you had asked for your salary, so if there was a way to end this and just sort of pay you your money, have some sort of written agreement you all won’t talk to each other anymore and move on,” Koretz told Rivas a week after the camera discovery, according to a recording of the call obtained by The Post. “So the police [investigation], that will end, and you’ll all move on.”

Rivas replied: “Eileen, I just can’t let something like this go. I don’t know whose intentions they were . . . I don’t know how many videos there are of me, if this was the first. It will be the last.”

Koretz eventually resigned as a judicial hearing officer amid a state inspector general probe into her meddling in the Rivas case.

While waiting a year for prosecutors to press criminal charges, Rivas filed a civil suit against the couple in January 2019.

Manhattan Civil Court Judge Lynn Kotler recently put the case on hold, pending the outcome of the criminal probe, which is ongoing, according to Brooklyn DA spokesman Oren Yaniv.

Yaniv declined to comment on Seltzer’s defense.

White said the Brooklyn DA’s office informed his team of the new alibi in October, and said prosecutors were seeking proof that Seltzer had a history of watching himself disrobe.

“The DA stated they are in the process of recovering deleted data off the camera that Vanessa found, but they appear to be trying to substantiate his defense by recovering deleted files,” White said.

He blasted the “ridiculous” defense.

“If I was a criminal attorney and I tried to pass off a defense with this many holes in it, I would expect any self-respecting law enforcement professional to laugh in my face or worse. I would deserve it,” he said.

Rivas’ lawyer vows to press forward despite the “fetish” alibi.

“This recent development in a case which has already included so many apparent abuses of power has shaken my faith in the criminal justice system,” White said.

“But we have no intention of letting him off the hook.”

Seltzer and his wife did not return repeated messages seeking comment. Seltzer’s lawyer, James Carman, declined to comment.