Hope this is right and that you can follow it.
Say age difference is y years.
Ages now are 40 and (40 - y)
When the younger was 10, the older was (10 + y) , but when the younger was 10, the older was (40-y) which is the younger's present age.
So 10 + y = 40 - y. So 2y = 30 , and y = 15.
So the age differnce is 15, and the ages are 40 and 25. When the older was 25, the younger would have been 10. (Q.E.D.)