Nope, as DragonPulse says, this has no risk. You had your shorts on, and STDs don't go through clothing. To get an STD, you need to have some kind of contact - oral to genital, genital to genital, or genital to anal - to get an STD.
As their name indicates, Sexually Transmissible diseases are transmitted by sexual activities, that can be anal/vaginal or oral. Some of them can also be transmitted by sharing needles to inject drugs or other sharp objects. Syphilis and herpes can be transmitted by touching the lesions they cause on the skin.
Masturbating and rubbing are not ways STDs are transmitted. Rubbing genitals can help to transmit some parasites that live attached to the body hair.But that was not your case as you were not rubbing any other person's genitals.
All the best.