A stretch that works for me and a derivation of the one you suggested.
Lie on your back, pull your knees towards your chest keeping feet flat on the floor. When your knees are at the highest point lock your knees together and also ankles, then under control push your legs over to one side keeping knees/ankles locked to the horizontal, then bring back to the vertical, repeat for the other side. I used to do 10 reps for each side.
This exercise should be done slowly, under control and not pushed if you body is fighting it. You should also try to keep your backside flat on the floor. The exercise puts a good twist on your spine and relieved the pain when my back was knacked.
Still use it now just to keep my back supple. As others have said, Brufen will work but is not a long term solution, for that you need opiates!
Hope it is sorted soon, you have my sympathy.