Hey m8
Nothing to be worried about... In my experience these can happen for various reasons:
1- Fatigue. Most obvious answer I guess but yeah, if you're tired, if you've had too much sex before (or masturbation I guess...) then you can experience this. This happens to me from time to time with my gf. We have a very active sex life and sometime the body just can't keep up... If you're REALLY tired then you will simply put lose your erection completely.
It's important to give your body some time to rest.
2- Losing focus. I don't know how else to put it... Sometime you might be worried about something, thinking about something else WHILE having sex. I mean you're right there, having sex, and bam out of nowhere, you start thinking about something else. Result? You lose your erection. Focus on your girl again and bam, you're in control again. So to avoid this, just keep your mind focused on what you're doing...