And if your doctor didn't mention it, ALWAYS urinate within 15 minutes of having sex. Many women get urinary tract infections from sexual fluids making their way to the woman's urethra. Peeing gets rid of them, where as not peeing will let the fluids travel further up into your bladder which often leads to infection. Because many women get bladder infections like this, I would imagine that's part of the reason to be advised to not have sex right now. But sadly, I believe the same would go for masturbation too. Your own vaginal fluids in the wrong place at the wrong time can cause a UTI, so it may make the problem worse.
Having a UTI while pregnant can lead to premature labour. The risk should pass once the infection is cleared up, but good friends of mine delivered at 6 months because she had a UTI. (After a few months in the Neonatal Intensive Care Unit she was fine and healthy enough to come up). I'm not telling you to try to scare you, but so that you are aware of just how important this is. Please, call your doctor for their take on whether you can masturbate or if you should hold off.