It is a horrible thing to hear and awful of him to say. Sometimes people do just get carried away with a conversation when they've had a few (I am by no way excusing it) and say a bit more than they mean to.
Wait until the friend has gone tomorrow. Ask him to sit down for a chat.
Say to him.
When you got in last night and you and your friend were chatting, I was awake and heard everything you said. I am extremely hurt and disappointed in you, that you think so little of me to say such things. If he asks to what you are referring, then say that you heard him tell his friend that the marriage was stale. (Because thats the most important issue here). You are really hurt that he chose to tell his friend instead of addressing it with you. Then see what he says. If he says 'oh it was just a laugh/banter, some other rubbish excuse' then say well there must be some truth in it otherwise you wouldn't have said it. Try to resolve that one if you can, then bring up the comments about your friend. Focus on how hurtful that was because it damaged your self esteem, and really upset you.
The essential thing is to stay utterly calm throughout it so you get your point across. No yelling! Impress upon him how hurt you are, the seriousness of how betrayed you feel.
He should apologise profusely, say he realises he should have spoken to you (he may say that he just wanted to speak to his friend about it - and tbf we've all have convos with friends about our OH's before speaking to them) and then there should be some major grovelling.
If he genuinely feels things are getting stale, then do listen to his reasons and try to find a way that you could counter that or change it. However he should still be apologising for hurting you.
If his attitude is rubbish about it, that you shouldnt have been listening or he didnt mean it or you are just being silly, try again to impress upon him how hurt you are, if he is still a tit about it, then you've got license to ask him to leave until he has something useful to say about it.