Does this happen all the time?
Or can you masturbate successfully? If it only happens with your g/f, then it's probably anxiety and your penis is telling you something (like maybe you're not ready for sex yet). If it happens all the time (like you cannot masturbate), then it's either anxiety/guilt, etc (I suppose that can be there when you're alone), or something physical or some unfortunate combo of the 2.
All I can say is that most Doctors are pretty cool hearing about sexual/penis things, it's no biggie for them. Just tell him and find out what's wrong.