Two recent cases of sex crimes involving children illustrate the barriers faced by prosecutors who want people facing serious charges to stay locked up in jail before trial. Both happened in Lawrence. And while the circumstances are quite different, both involve grown men accused of aggravated rape of a child — a crime apparently not serious enough, as far as Massachusetts law is concerned, to keep someone in jail, without the opportunity to make bail.

Gov. Charlie Baker has been tilting at this problem for months as part of a wider effort to tighten up bail rules for criminal defendants. His legislation remains parked in a committee on Beacon Hill. It’s past time for lawmakers to vote it out. To borrow words used by Essex District Attorney Jonathan Blodgett earlier this week to address this shortcoming, it is “simply astonishing” that this legal loophole is allowed to persist.

That it does was highlighted by the case involving Carlos Vieira, a Lawrence police officer arrested in February and accused of having sex with a 13-year-old boy he'd connected with via social media. Vieira was charged with two counts of aggravated child rape, as well as two counts of assault and battery on a child under age 14.

Neither charge gives prosecutors grounds to request a dangerousness hearing, wherein a judge can weigh information such as a defendant’s criminal history in deciding whether they should be eligible for release on bail. Baker want to expand the law to include aggravated child rape and a broader selection of other crimes, among those that can trigger such a hearing.

Viera was released on $10,000 bail once a justice on the Supreme Judicial Court had ruled that he must b given a bail hearing. In the meantime, Baker has cited the case as an example of the need for bail reform.

“We know there are a lot of victims groups and folks in law enforcement who are anxious to see the dangerousness statute expanded,” the governor told reporters early last month, as noted by Statehouse reporter Christian Wade,. “I think that would be great if that happens, but I get the fact that there’s a lot of push coming from a variety of different directions on it.”

Some of the criticism is leveled by advocates who say the bail reforms threaten to undo the progress of recent changes to the criminal justice system, and that there’s no empirical evidence of the need for a broader lens applied to the dangerousness statute.

But then comes a case like the one against Carlos Rivera, 47, who is accused of sexually assaulting two teenagers and leaving one of them, Chloe Ricard, 13, of Amesbury, at the Lawrence General Hospital emergency room to die. There is much the public still does not know about the relationship between Rivera, Ricard and another teenager. Prosecutors have sought to keep him in jail without bail due to charges that he gave drugs to minors and committed indecent assault and battery on a person over 14.

Paradoxically, even though Rivera faces a more serious charges of aggravated rape of a child, it's not grounds for such a dangerousness finding.

That prompted this week's commentary from Blodgett: “I am reluctant to use the horrifying facts of this case to illustrate the necessity for immediate action to address the glaring loophole in the dangerousness statute, but I’m concerned about the public’s safety. The law does not allow us to petition the court to hold a man accused of raping a 13-year-old innocent girl but does allow us to file because he allegedly touched a 16-year-old girl inappropriately. That is simply astonishing and must be addressed by the Legislature immediately.”

We too are concerned about the public’s safety. There should be little doubt in the Legislature about the need to update the statute, or the fairness to the criminally accused.

Bail laws and related statutes exist to ensure defendants return to court to face charges against them. Certainly some offenses are so heinous that a charge itself should warrant more careful deliberation about whether the accused gets a crack at release before trial.

Judges, even with Baker's reforms, continue to be arbiters of who gets that opportunity. But in serious cases, prosecutors should be allowed to make the case that turning someone back onto the streets will endanger the community.

It's nonsensical and frightening that aggravated child rape is not among the eligible offenses for that consideration. It is up to lawmakers to quickly button up this glaring omission.