I ran into exactly the same bug when I tried to move the not-so-nice environment variables out of my profile and into the lesskey file. Ultimately I never got around to finding out why it wouldn’t work - but together with someone else, came up with a small C wrapper around less(1) which lets the user set colours in a more sane manner.
With this, you only have to do:
See here for a more detailed description along with the source code.
This is great, I like that it avoids polluting the shell environment.
The issue should be fixed in the most recent less version (released just 10 days ago) but most systems won’t have this up-to-date version so there is still a need for a solution like yours to set the variables elsewhere.