I had always assumed that it had something to do with taking severed heads away in baskets in the bloody aftermath of the French Revolution, but the most likely answer is that it is "an English alliterative phrase of unclear origin," to quote one of the above mentioned sources.