Sort threads by id