Once or twice masturbation is ok. But this is very person to person. May be it affects you more than others. Try to defocuse you r mind from sex.
before sleep. Don't think too much of sex. You can also take homeopathic medicine for this condition. You are free to consult me personally.