The type of bacteria in your mouth may affect your memory, attention and thinking abilities, a study suggests.