Dear AZ_Larki,
The short answer to your question is, it depends on the man. For some men, what you are describing occurs post-40. It's simply age appropriate diminishing levels of testosterone; however, depending on pre-andropausal levels, general health, genetic predisposition and other factors too numerous to describe here, the normal but gradual lowering of T in middle-aged men can manifest itself in a variety of ways.
Can men at that age expect the situation to improve? Well yes, they can, if they can raise their androgen levels, either naturally through vigorous exercise and lifestyle changes [if need be], or by administering supplemental levels of testosterone and even possibly growth hormones, although the latter is extremely controversial. If they don't do anything and keep on living the typical westernized lifestyle of weight gain and less exercise, then it would stand to reason that things will NOT improve - in fact, things will usually get worse, what with higher insulin levels, higher blood pressure, cardiac issues, erectile dysfunction and an assortment of other sequelae afflicting a middle-aged sedentary male in the Western world.
Now, it's not necessarily the norm for a man just shy of 40 to lose interest in sex. Either they lost interest in you, or they really were in a hypogonadal state, for reasons unknown to us at this point.
Another aspect to all this is that the man may not necessarily "lose interest" - it may be that his focus has somewhat shifted, from a sex-hungry guy who needs immediate satisfaction, to someone slightly more reflective and choice-oriented when it comes to sex. This means that the lower testosterone levels can afford him to be less "desperate," less eager and more interested in the totality of an experience with a woman who mirrors his state of mind. At first, such a man may become surprised at this shifting state of body/mind integration, and then he may find that he really enjoys the journey and not just the destination. This type of shift can take months, sometimes even a few years, during which he may express himself as "having lost interest," when in fact he just needs to regain his new bearings.
I find it very interesting that in my survey [which I will be submitting for publication soon, if nothing else so that I can share the results with you all], a majority of respondents preferred women 26 and over. A fair amount preferred women 31-35. It seems to me that among the men who responded (mean age was 49.5!!!), there was a certain wish to engage with someone who more closely mirrored their own state of being [at the time of the survey.] I found this very encouraging and very human - it shows that these men are genuinely looking for someone who responds to their needs, more than just a perfect face or body. And that really does seem indicative of someone who has reconstructed the concept of what good sex really means.
It's no longer the destination, it's the journey,
The Love Goddess