Scans of nearly 600 middle-aged people showed sleeping badly was associated with poorer brain health years later.