A Philadelphia judge on Monday dismissed all charges against two former police officers who were arrested and charged in September with illegally detaining a man in East Mount Airy five months earlier.

Municipal Court Judge Thomas Gehret dismissed the charges against former Philadelphia Officers Matthew Walsh, 30, and Marvin Jones, 48, after a preliminary hearing. They had been charged with tampering with the public record — a third-degree felony — and misdemeanor counts of obstructing the administration of law, false imprisonment, official oppression, and conspiracy.

The alleged victim, Jordan Elijah, 26, of West Mount Airy, testified that about 10 a.m. April 17, he stepped into a grocery store on Sharpnack Street near Ross Street to order something to eat when Walsh grabbed him from the back of his belt and told him to walk out of the store.

He said Walsh and his partner, Jones, then searched him outside the store, put him in the back of their police SUV, and went to search his black Chevrolet Tahoe, which was parked across the street. The officers then returned to their vehicle and drove off with him, handcuffed in the back seat, Elijah testified. He said he asked the officers if he was under arrest, and that they replied that he was not. About a block north on Ross Street, he said, the police vehicle stopped and Walsh let him out.

Elijah testified that the officers had taken four oxycodone pills from a bag of pills in his possession. He contended that the officers harassed him and illegally detained and searched him. He said he went to the 14th District afterward and complained about being detained and about his missing pills.

Walsh's attorney, Fortunato Perri Jr., argued that the officers questioned and frisked Elijah because they knew him — Walsh had previously arrested him in a drug-and-gun case — and suspected him of having illegal drugs. He contended that the officers searched the Tahoe after Elijah said he had a prescription for his pills inside. He contended that the officers found the prescription, but decided to drive the police vehicle, with Elijah in it, away from the scene for about a block to allow a UPS vehicle to pass on the street.

Perri and attorney Bill Davis, who represented Jones, contended that the officers didn't steal any of Elijah's pills.

Elijah testified under cross-examination by Perri that the officers did not find his oxycodone prescription in his Tahoe that morning. (He told a reporter after the hearing that he used the pills for pain, and had later shown his prescription to the police Internal Affairs Division, which was investigating his complaint.)

Perri contended that the officers had a right to stop and frisk Elijah and contended that they eventually let him go after realizing he had a prescription for the pills in his Tahoe. The officers shouldn't have been arrested and charged, he argued.

"Are we going to lock up every cop every time there's a bad search?" Perri said before the judge. "We shouldn't. This has got to stop."

Assistant District Attorney Tracy Tripp argued that the officers had committed "official oppression" by keeping Elijah handcuffed in the police vehicle for 20 minutes and then "cruising" with him for about a block before letting him go. "They're disrespectful," she said.

Of the prior arrest of Elijah by Walsh, Tripp told the judge that Elijah had a legal permit to carry a gun at that time and that the drug charges against him were eventually dismissed after the drug evidence against him was suppressed following a court hearing.

She said after Monday's hearing that she disagreed with the judge's ruling and planned to refile the charges against Walsh and Jones.

Lt. Brian Hartzell of Internal Affairs testified that police did not find Elijah's alleged missing pills in the officers' vehicle or lockers. He said Walsh and Jones, in their documentation for stopping and frisking Elijah, said they observed him in a high-crime area known for drugs, but wrote on their document that no evidence of contraband was recovered from Elijah.

Walsh and Jones were fired from the Police Department after their arrests. Perri said after the hearing that they hope to get their jobs back.