Inflation accelerated to 3.5% from 3.1% in the year to September, according to the Office for National Statistics (ONS).