Leicestershire's Rehan Ahmed was denied a hat-trick of wickets against Yorkshire as he staked his claim for a place in England's Ashes squad.