Neuter/spay them. Else use diapers or separate them from each other. You can go for medical procedures such as neutering in male dogs and spaying in females to surgically remove their reproductive organs and thus, stop them from mating in heat.  You can be assured that the procedure is quite simple and there are no risks involved to the body of the animals. There are several benefits of sterilizing your dogs, such as limited sexual activity, reduced chances of hormonal diseases, reduced aggression, no risk of pregnancy, and more.