The 22-year-old joined Cardiff in 2015 but has made just 22 senior appearances for the Bluebirds, spending time out on loan at Port Vale and Plymouth Argyle during the past two seasons.
Kennedy will return to League One next season too, having penned a temporary deal with Portsmouth until the end of the current campaign.
"Matty's a very skilful attacking midfielder with the great ability to go past players," manager Kenny Jackett told the club's official website.
"He also has a good record of assists and will be able to provide for our strikers with quality crosses.
"He played against us in the Carabao Cup and produced an impressive performance, so I'm sure he'll be a very effective player for us."