Is your dog fixed? If it isn't, then his 'behavior' is going to continue until you do.
If your dog is fixed, and this is just something he does, I have one suggestion I could offer.
I worked at a pet store for a few years, and there is actually an um... sex toy for dogs, essentially. It sort of looks like one of those hand-held back massagers in shape (that 4-prong thing) but its dog-sized. It comes with a spray that is meant to mimic the hormones from a female in heat, and you put this 'object' in the corner of your house somewhere that is genuinely out of sight. Its made of a type of plastic that is easy to clean, and its meant to encourage your dog to act out its behavior on that. It should stop your dogs penis from becoming 'unsheathed' to the point where you have to do something about it. This is actually something designed for dogs who aren't fixed, can't breed, etc. They're going to have natural instincts and this just offers you a somewhat better option then just having him hump your furniture and well, whatever it wants. Unfortunately animals are sexual beings, and aside from you doping him up to the point where he just lays there all day (horrible quality of life for you dog!) I don't think there is much you can really do other then behavioral training.
Good luck!