A high school history teacher in Grantsburg, Wis., encouraged two of his female students to share their personal thoughts and feelings with him and then invited them on separate occasions to his house in Stillwater, where he had sex with them, according to charges filed Thursday in Washington County District Court.

Matthew Robert Koenen, 36, lured two 16-year-old girls to his house after "countless conversations" on cellphones and e-mail accounts he hid from his wife, the charges said. Koenen was charged with two counts of third-degree criminal sexual conduct. The alleged victims, identified in the criminal complaint only by their initials, were students at the school in 2012.

Koenen was asked to resign after he admitted to school officials that he had exchanged text messages of a personal nature with one of the girls, the charges said.

The former teacher, booked into the Washington County jail on Thursday evening, had coached students at Grantsburg High School who were members of a National History Day group that traveled to Washington, D.C. He knew one of the girls from that trip and was her mentor and confidant, the charges said. Their relationship became "romantic in nature," and in August 2012 they had sex in Koenen's bedroom after he put his child down for a nap, the charges said.

Koenen became involved with the second girl in May 2012, when he confronted her about slipping grades, the charges said, and allegedly had sex with her in his bedroom three weeks after the first girl.

Sexual relationships with both girls continued after the initial encounters, the charges said.

When Koenen became aware that police were investigating him, he wrote an e-mail to the second girl in May that read, "important question, tell me what you told the cops when questioned about dirty flirty messages," the charges said.

The investigation revealed that at least two other female students had visited the defendant's home in Stillwater while his wife, also a teacher at the school, was away, the charges said.

The matter was investigated by the Stillwater Police Department. Grantsburg school officials couldn't be reached for comment.

"This office will continue to take a leading role in condemning those in positions of authority from abusing that relationship and preying upon those too immature or needy to make good judgments and to resist," Washington County Attorney Pete Orput said. "We will be there for these victims. Rest assured at that."