Keeping active throughout life – particularly before the age of 50 – leads to changes in the brain that could help stave off dementia, according to a study.