The "two year difference" depends on the state. For instance in Texas:
Texas Penal Code Sec. 22.011(e) It is an AFFIRMATIVE defense to prosecution under Subsection (a)(2):
(2) that: (A) the actor [criminal defendant] was not more than THREE years older than the victim and at the time of the offense:
... AND (B) the victim: (i) was a child of 14 years of age or older;
------
Every crime or civil grounds for suing ("cause of action") has "elements". The Plaintiff/Prosecution must show that each element has occurred. For instance, sexual activity with someone under the age of 17.
"AFFIRMATIVE" defense means that the DEFENSE can show ADDITIONAL FACTS that CHANGE the result. (No more than 3 years AND victim is at least 14 AND consensual.)
So, for instance, in Texas an 18-year old having consensual sex with a 16-year old is not a crime.